package com.stylefeng.guns.modular.netcar.service.impl;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.stylefeng.guns.core.model.CommonKeyValue;
import com.stylefeng.guns.core.model.Pager;
import com.stylefeng.guns.modular.netcar.dao.LineDisableDateMapper;
import com.stylefeng.guns.modular.netcar.model.LineDisableDate;
import com.stylefeng.guns.modular.netcar.service.ILineDisableDateService;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.toolkit.IdWorker;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**

 * 线路禁用日期 Service 实现 
 * @author 张亚林
 * @Date 2018-10-27 09:52
 */
@Service
public class LineDisableDateServiceImpl extends ServiceImpl<LineDisableDateMapper,LineDisableDate> implements ILineDisableDateService {

    @Resource
    private LineDisableDateMapper lineDisableDateMapper;

    /**
     * 删除线路禁用日期
     * @param lineDisableDate
     * @return     
     */
    @Transactional
    public int deleteLineDisableDate(LineDisableDate lineDisableDate,String token)throws Exception{
        if(lineDisableDate==null ){
            throw new RuntimeException("参数不全！");
        }
        return this.lineDisableDateMapper.deleteLineDisableDate(lineDisableDate);
    }
    /**
     * 批量删除线路禁用日期
     * @param ids 主键ID数组
     * @return 
     */
    @Transactional
    public int deleteBatchLineDisableDate(String[] ids,String token)throws Exception{
        return this.lineDisableDateMapper.deleteBatchLineDisableDate(ids);
    }
    /**
     * 查询线路禁用日期列表
     * @param lineDisableDate 线路禁用日期对象
     * @return
     */
    public List<LineDisableDate> selectListLineDisableDate(LineDisableDate lineDisableDate,String token)throws Exception{
        return  this.lineDisableDateMapper.selectListLineDisableDate(lineDisableDate);
    }
    /**
	 * 分页查询线路禁用日期列表
     * @param pager 分页对象
     * @return
     */     
    public  Map pageListLineDisableDate(Pager pager,String token) throws Exception{
        Page page=new Page(pager.getPageNumber(),pager.getPageSize());
        page.setRecords(lineDisableDateMapper.selectListLineDisableDate(page,(LineDisableDate)pager.getObj()));
        List<LineDisableDate> list = page.getRecords();
        Map mapDate = new HashMap();
        mapDate.put("rows", list);
        mapDate.put("total", page.getTotal());
        mapDate.put("page", page.getCurrent());
        mapDate.put("pageCount", page.getPages());
        return mapDate;
    }
    /**
     * 同一个事务 互斥锁查询
     * @param lineDisableDate 线路禁用日期对象
     * @return 
     */
    public  List<LineDisableDate> selectListLineDisableDateForUpdate(LineDisableDate lineDisableDate)throws Exception{
        return  this.lineDisableDateMapper.selectListLineDisableDateForUpdate(lineDisableDate);
    }
    /**
     * 通过主键id查询的线路禁用日期列表
     * @param id 主键id
     * @return     
     */
    public  LineDisableDate findLineDisableDateById(String id,String token)throws Exception{
        return  this.lineDisableDateMapper.findLineDisableDateById(id);
    }

    /**
     * 新增线路禁用日期数据
     * @param lineDisableDate  线路禁用日期对象
     * @return
     */
    @Transactional
    public int insertLineDisableDate(LineDisableDate lineDisableDate,String token) throws Exception { 
        if(lineDisableDate!=null && (lineDisableDate.getLddId()==null || lineDisableDate.getLddId().trim().length()<10)){
            lineDisableDate.setLddId(IdWorker.get32UUID());
        }  
        return this.lineDisableDateMapper.insertLineDisableDate(lineDisableDate);
    }
    
    /**
     * 更新线路禁用日期数据
     * @param lineDisableDate 线路禁用日期对象
     * @return     
     */
    @Transactional
    public int updateLineDisableDate(LineDisableDate lineDisableDate,String token) throws Exception {     	
        return  this.lineDisableDateMapper.updateLineDisableDate(lineDisableDate);
    }    
    /**
     * 查询线路禁用日期返回key-Value属性
     * @param lineDisableDate 系统操作对象
     * @return     
     */
    public List<CommonKeyValue> optionsLineDisableDate(LineDisableDate lineDisableDate,String token) throws Exception {
        List<LineDisableDate> listLineDisableDate=this.lineDisableDateMapper.selectListLineDisableDate(lineDisableDate);
        List<CommonKeyValue> listOptions=new ArrayList<CommonKeyValue>();
        for(LineDisableDate item:listLineDisableDate){
            CommonKeyValue opts=new CommonKeyValue();
            opts.setId(""+item.getLddId());
            opts.setValue(item.getOlId());
            listOptions.add(opts);
        }
        return listOptions;
    }
}
